#include "wxsbaseproperties.h"
#include "wxsflags.h"
#include <globals.h>

using namespace wxsFlags;

void wxsBaseProperties::OnEnumProperties( long Flags ) {
  static const int Priority1 = 60;
  static const int Priority2 = 50;
  bool NotXml = !( Flags & flXml );
  bool NotRoot = !( Flags & flRoot );
  bool Root = ! NotRoot;
  bool NotSource = !( Flags & flSource );
  bool Source = ! NotSource;
  bool Pointer = !!( Flags & flPointer );
  bool VISFilter = NotXml && NotRoot;
  bool PSFilter = Root && Source;
  if( Flags & flVariable && VISFilter ) {
    WXS_SHORT_STRING_P( wxsBaseProperties, m_VarName, _T( "组件名" ), _T( "var_name" ), _T( "" ), true, Priority1 );
  }
  if( Flags & flVariable && VISFilter && Pointer ) {
    WXS_BOOL_P( wxsBaseProperties, m_IsMember, _T( "是部件" ), _T( "var_is_member" ), true, Priority1 );
  }
  if( Flags & flId && VISFilter ) {
    WXS_SHORT_STRING_P( wxsBaseProperties, m_IdName, _T( "标识符" ), _T( "identifier" ), _T( "" ), true, Priority1 );
  }
  if( Flags & flSubclass && VISFilter ) {
    WXS_SHORT_STRING_P( wxsBaseProperties, m_Subclass, _T( "类名" ), _T( "subclass" ), _T( "" ), false, Priority1 );
  }
  if( Flags & flPosition ) {
    WXS_POSITION_P( wxsBaseProperties, m_Position, _T( "缺省pos" ), _T( "X" ), _T( "Y" ), _T( "以对话单位表示的位置" ), _T( "pos" ), Priority2 );
  }
  if( Flags & flSize ) {
    WXS_SIZE_P( wxsBaseProperties, m_Size, _T( "默认尺寸" ), _T( "宽" ), _T( "高" ), _T( "对话框单位大小" ), _T( "size" ), Priority2 );
  }
  if( Flags & flValidator && Source ) {
    WXS_SHORT_STRING_P( wxsBaseProperties, m_Validator, _T( "验证器" ), _T( "validator" ), _T( "" ), false, Priority2 );
  }
  if( Flags & flEnabled ) {
    WXS_BOOL_P( wxsBaseProperties, m_Enabled, _T( "启用" ), _T( "enabled" ), true, Priority2 );
  }
  if( Flags & flFocused ) {
    WXS_BOOL_P( wxsBaseProperties, m_Focused, _T( "焦点" ), _T( "focused" ), false, Priority2 );
  }
  if( Flags & flHidden ) {
    WXS_BOOL_P( wxsBaseProperties, m_Hidden, _T( "隐藏" ), _T( "hidden" ), false, Priority2 );
  }
  if( Flags & flColours ) {
    WXS_COLOUR_P( wxsBaseProperties, m_Fg, _T( "前景" ), _T( "fg" ), Priority2 );
  }
  if( Flags & flColours ) {
    WXS_COLOUR_P( wxsBaseProperties, m_Bg, _T( "背景" ), _T( "bg" ), Priority2 );
  }
  if( Flags & flFont ) {
    WXS_FONT_P( wxsBaseProperties, m_Font, _T( "字体" ), _T( "font" ), Priority2 );
  }
  if( Flags & flToolTip ) {
    WXS_STRING_P( wxsBaseProperties, m_ToolTip, _T( "工具提示" ), _T( "tooltip" ), _T( "" ), false, Priority2 );
  }
  if( Flags & flHelpText ) {
    WXS_STRING_P( wxsBaseProperties, m_HelpText, _T( "帮助文本" ), _T( "help" ), _T( "" ), false, Priority2 );
  }
  if( Flags & flMinMaxSize && Source ) {
    WXS_SIZE_P( wxsBaseProperties, m_MinSize, _T( "默认Min尺寸" ), _T( "Min宽" ), _T( "Min高" ), _T( "Min会话尺寸" ), _T( "minsize" ), Priority2 );
  }
  if( Flags & flMinMaxSize && Source ) {
    WXS_SIZE_P( wxsBaseProperties, m_MaxSize, _T( "默认Max尺寸" ), _T( "Max宽" ), _T( "Max高" ), _T( "Max会话尺寸" ), _T( "maxsize" ), Priority2 );
  }
  if( Flags & flExtraCode && Source ) {
    WXS_STRING_P( wxsBaseProperties, m_ExtraCode, _T( "附加码" ), _T( "extra_code" ), _T( "" ), false, Priority2 );
  }
  if( PSFilter ) {
    WXS_BOOL_P( wxsBaseProperties, m_ParentFromArg, _T( "Use parent from argument" ), _T( "parent_arg" ), true, Priority2 );
  }
  if( Flags & flId && PSFilter ) {
    WXS_BOOL_P( wxsBaseProperties, m_IdFromArg, _T( "Use ID from argument" ), _T( "id_arg" ), true, Priority2 );
  }
  if( Flags & flPosition && PSFilter ) {
    WXS_BOOL_P( wxsBaseProperties, m_PositionFromArg, _T( "Use pos from argument" ), _T( "pos_arg" ), false, Priority2 );
  }
  if( Flags & flSize && PSFilter ) {
    WXS_BOOL_P( wxsBaseProperties, m_SizeFromArg, _T( "Use size from argument" ), _T( "size_arg" ), false, Priority2 );
  }
  if( m_StyleSet ) {
    WXS_STYLE_P( wxsBaseProperties, m_StyleBits, _T( "风格" ), _T( "style" ), m_StyleSet, Priority2 );
  }
  if( m_StyleSet ) {
    WXS_EXSTYLE_P( wxsBaseProperties, m_ExStyleBits, _T( "扩展风格" ), _T( "exstyle" ), m_StyleSet, Priority2 );
  }
}

void wxsBaseProperties::AddQPPChild( M_Code_unused wxsAdvQPP* QPP, M_Code_unused long Flags ) {
}

void wxsBaseProperties::SpecialXmlRead( TiXmlElement* Element, bool IsXRC, bool IsExtra ) {
  if( IsXRC ) {
    m_IdName = cbC2U( Element->Attribute( "name" ) );
    m_Subclass = cbC2U( Element->Attribute( "subclass" ) );
  }
  if( IsExtra ) {
    m_VarName = cbC2U( Element->Attribute( "variable" ) );
    const char* MbrText = Element->Attribute( "member" );
    m_IsMember = !MbrText || !strcmp( MbrText, "yes" );
  }
}

void wxsBaseProperties::SpecialXmlWrite( TiXmlElement* Element, bool IsXRC, bool IsExtra, long Flags, const wxString& ClassName ) {
  if( !( Flags & flRoot ) ) {
    if( IsXRC ) {
      if( Flags & flId ) {
        Element->SetAttribute( "name", cbU2C( m_IdName ) );
      }
      if( Flags & flSubclass ) {
        if( !m_Subclass.IsEmpty() && ( m_Subclass != ClassName ) ) {
          Element->SetAttribute( "subclass", cbU2C( m_Subclass ) );
        }
      }
    }
    if( IsExtra ) {
      if( Flags & flVariable ) {
        Element->SetAttribute( "variable", cbU2C( m_VarName ) );
        Element->SetAttribute( "member", m_IsMember ? "yes" : "no" );
      }
    }
  }
}

